<?php

namespace App\Service\CallingCards;

use App\Exceptions\Custom\CustomException;
use App\Library\Freeker\FreekerApi;
use App\Models\FeishuCallingCard\FeishuCallingCard;
use App\Models\FeishuCallingCard\FeishuCallingCardFranchiseeClue;

class ThirdClueService
{
    public static function checkSign(int    $cardId, string $name, string $mobile, int $timestamp, string $province,
                                     string $city, string $sign, string $remark)
    {
        if (abs(time() - $timestamp) > 3600) {
            throw new CustomException('时间戳不正确，请检查调用端是否正确');
        }
        $signed = md5("{$cardId}_{$name}_{$mobile}_{$province}_{$city}_{$timestamp}_{$remark}_" . config('calling-cards.secretKey'));
        if (strtolower($sign) !== strtolower($signed)) {
            throw new CustomException('签名不正确，请检查算法和密钥');
        }
        $card = FeishuCallingCard::find($cardId);
        if (null === $card) {
            throw new CustomException('不存在的加盟名片ID，请核实');
        }
    }

}
